import { ref } from 'vue'
import { defineStore } from 'pinia'

// 定义并导出用户store
export const useUserStore = defineStore('user', () => {
  // 状态 (state)
  const username = ref('')
  const isLoggedIn = ref(false)

  // 动作 (actions)
  function setUsername(newUsername) {
    username.value = newUsername
    isLoggedIn.value = true
  }

  function logout() {
    username.value = ''
    isLoggedIn.value = false
  }

  // 返回需要暴露的状态和方法
  return { 
    username, 
    isLoggedIn, 
    setUsername, 
    logout 
  }
})
